package com.shop.product.controller;



import com.shop.common.response.ExceptionResponse;
import com.shop.product.model.ProductInfo;
import com.shop.product.service.ProductInfoServiceImpl;
import com.shop.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
@Slf4j
public class IndexController {
    @Autowired
    private ProductInfoServiceImpl productInfoService;
    @Autowired
    private ProductService productService;
    @GetMapping("index/{productId}")
    public ProductInfo index(@PathVariable String productId, @RequestHeader(value = "token", required = false) String token , @Param("params") String params) {

        log.info("token: {} params:{}", token, params);
        return productInfoService.getProductInfo(productId);
    }

    @GetMapping("recommendProduct")
    public ResponseEntity<ExceptionResponse> RecommendProduct(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize) {
        List<ProductInfo> productInfoList =  productService.ProductStatusAndRecommend(pageNum,pageSize);
        return ResponseEntity.ok(ExceptionResponse.Success(productInfoList));
    }

    @GetMapping("user")
    public String user(String username){
        //log.info("用户id: {}", JwtUtils.getUserId());
        return username;
    }
}
